import config from './config.js' //引入地址文件
export default (url, data = {}, method = 'GET') => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: config.host + url,
			data,
			method,
			header: {
				cookie: uni.getStorageSync('cookies') ? uni.getStorageSync('cookies').find(im => im
					.indexOf('MUSIC_U') !== -1) : ''
			},
			// header:{cookie:uni.getStorageSync('cookies')?uni.getStorageSync('cookies').find((im)=>{im.indexOf('MUSIC_U')!==-1}):''},
			success: res => {
				if (data.isLogin) {
					resolve(res)
					uni.setStorageSync('cookies', res.cookies)
				} else {
					resolve(res.data)
				}
			},
			fail: err => {
				reject(err)
			}
		})
	})
}
